<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<!--    <meta charset="utf-8">-->
    <meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />
    <title>添加用户--layui后台管理模板 2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="resources/css/public.css" media="all"/>
</head>
<body class="childrenBody">
<form class="layui-form" style="width:80%;" lay-filter="dataFrm" id="dataFrm">
    <div class="layui-form-item layui-row layui-col-xs12">
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">商家名称:</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input mName" lay-verify="required" name="mName" placeholder="请输入用户名">
            </div>
        </div>
        <label class="layui-form-label">手机号:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input telephone" lay-verify="required" name="telephone"
                   placeholder="请输入手机号">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">营业执照编码</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input mLicensenum" lay-verify="required" name="mLicensenum"
                   placeholder="请输入营业执照编码">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">详细地址</label>
        <div class="layui-input-block">
            <input type="button" value="选择地址" id="map" name="mAddress">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">联系方式</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input mContactway" lay-verify="required" name="mContactway"
                   placeholder="请输入联系方式">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">余额</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input balance"  name="balance"
                   readonly>
        </div>
    </div>


    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">营业执照正面:</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="mPositive">上传图片</button>
            <input type="hidden" id="mPositive1" name="mPositive">
            <div class="layui-upload-list">
                <img class="layui-upload-img" id="mPositive2"   width="200px" height="200px">
                <p id="demoText"></p>
            </div>
        </div>
    </div>

    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">营业执照反面:</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="mSide">上传图片</button>
            <input type="hidden" id="mSide1" name="mSide">
            <div class="layui-upload-list">
                <img class="layui-upload-img" id="mSide2"  width="200px" height="200px">
                <p id="demoText1"></p>
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="register">认证</button>
            <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary" onclick="parent.close();">取消</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script th:inline="none">
    var html = "";
    layui.use(['form', 'layer', 'table', 'laytpl', 'laydate', 'upload'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laytpl = layui.laytpl,
            table = layui.table,
            laydate = layui.laydate,
            upload = layui.upload;
         $.ajax({
             url:"findmerchantuser",
             type:"get",
             success:function (res) {

                     if (res.code==200){
                         $(".mName").val(res.data.mName);
                         $(".mPassword").val(res.data.mPassword);
                         $(".telephone").val(res.data.mPhonenum);
                         $(".mLicensenum").val(res.data.mLicensenum);
                         $(".mAddress").val(res.data.mAddress);
                         $(".mContactway").val(res.data.mContactway);
                         $(".balance").val(res.data.balance);
                         $('#mPositive1').val(res.data.mPositive);
                         $("#mSide1").val(res.data.mSide);
                         $.ajax({
                             url:"showImage",
                             type:"get",
                             data:{imageFileName:res.data.mPositive},
                             success:function (result) {
                                 $('#mPositive2').attr('src', result);
                             }
                         })
                     }
             }
         })
        $("#map").click(function () {
            var index=layui.layer.open({
                title: "详细信息",
                type: 2,
                content: "map.do",
                area: ['1000px', '500px'],
                success:function (res) {

                }
            })
        })

        //文件上传
        var uploadInst = upload.render({
            elem: '#mPositive' //绑定元素
            , url: '/uploadImage2.do' //上传接口,
            , method: 'post'
            , accept: 'images'
            , acceptMime: 'image/*'
            , field: 'mPositive'
            , done: function (res) {
                $('#mPositive1').val(res.data.fileName);
                if (res.code == 200) {
                    top.layer.msg(res.msg);

                } else  {
                    top.layer.msg(res.msg);
                  location.reload();
                }
            }
            , error: function () {
                var demoText = $('#demoText');
                demoText.html('<span style="color: #ff5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                })
            }
            , before: function (obj) {
                obj.preview(function (index, file, result) {
                   $('#mPositive2').attr('src', result);
                });
            }
        });


        //文件上传2
        var uploadInst = upload.render({
            elem: '#mSide' //绑定元素
            , url: '/uploadImage3.do' //上传接口,
            , method: 'post'
            , accept: 'images'
            , acceptMime: 'image/*'
            , field: 'mSide'
            , done: function (res) {
                $('#mSide1').val(res.data.fileName);
                if (res.code == 200) {
                    top.layer.msg(res.msg);

                } else  {
                    top.layer.msg(res.msg);
                    location.reload();
                }
            }
            , error: function () {
                var demoText = $('#demoText1');
                demoText.html('<span style="color: #ff5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                })
            }
            , before: function (obj) {
                obj.preview(function (index, file, result) {
                    $('#mSide2').attr('src', result);
                });
            }
        });
        //增加用户
        form.on("submit(register)", function (data) {
            var index = layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
            //实际使用时的提交数据
            var params = $("#dataFrm").serialize();
            $.post("/register.do", params, function (res) {
                if (res.code == 200) {
                    setTimeout(function () {
                        top.layer.close(index);
                        top.layer.msg("认证中，请稍后！");
                        //刷新父页面
                      location.reload();
                    }, 2000)
                }else {
                    top.layer.msg("认证失败！");
                    location.reload();
                }
            }, "json");
            return false;
        });

    })
</script>
</body>
</html>